package fr.insee.rome.io.writer;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Collection;

import fr.insee.rome.bean.Metier;

public class CsvRomeWriter implements RomeWriter {

	private FileWriter writer;
	private static RomeWriter instance = null;
	
	private CsvRomeWriter(){}
	
	public static RomeWriter getInstance(){
		if(instance == null){
			instance = new CsvRomeWriter();
		}
		return instance;
	}
	
	public void write(Collection<Metier> metiers) throws IOException {
		for (Metier metier : metiers) {
			writer.append(metier.getCode() + "=" + metier.getLibelle() + "\n");
		}
	}

	public void close() throws IOException {
		this.writer.close();
	}

	public void open(String path) throws IOException {
		this.writer = new FileWriter(path);
	}
}
